package xyz.zhouzhousag.controller;
/**
 * Description:
 * <p>
 * ClassName: ProductController
 * date: 2021/3/16 15:38
 *
 * @author Yin.Liu
 * @version 1.0
 * @since JDK 1.8
 */

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import xyz.zhouzhousag.domain.Product;
import xyz.zhouzhousag.service.IProductService;

import java.util.List;

/**
 *@ClassName ProductController
 *@Description TODO
 *@Author Yin.Liu8
 *@Date 2021/3/16 15:38
 *@Version 1.0
 */
@Controller
@RequestMapping("/product")
public class ProductController {

    @Autowired
    IProductService productService;

    @RequestMapping("/save.do")
    public String save(Product product){

        productService.save(product);
        return "redirect:findAll.do";
    }

    @RequestMapping("/findAll.do")
    public ModelAndView findAll(){
        ModelAndView modelAndView = new ModelAndView();
        List<Product> all = productService.findAll();
        modelAndView.addObject("productList",all);
        modelAndView.setViewName("product-list");
        return modelAndView;
    }

}
